package com.app.service.system

import com.app.cache.SessionHandler
import com.app.constant.CommonConstant
import com.app.mapper.TFunctionMapper
import com.app.model.TFunction
import com.app.service.BaseService
import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service


/**
 * Created by three on 14-8-4.
 */
@CompileStatic
@TypeChecked
@Service
class FunctionService extends BaseService<TFunction> implements IFunctionService{

    @Autowired
    public void setMapper(TFunctionMapper mapper) {
        super.baseMapper = mapper;
    }

    @Override
    Long addBasic(TFunction obj) throws Exception {
        TFunction func = obj as TFunction;
        func.setCreateUserId(SessionHandler.user().id);
        func.setCreateTime(new Date());
        func.setModifyUserId(SessionHandler.user().id);
        func.setModifyTime(new Date());
        func.setIsActive(CommonConstant.IsActive.TRUE.getValue() as Boolean)
        return baseMapper.insert(obj);
    }

    @Override
    void modifyBasic(TFunction obj) throws Exception {
        TFunction func = obj as TFunction;
        func.setCreateUserId(null);
        func.setCreateTime(null);
        baseMapper.updateByPrimaryKeySelective(func)
    }

    @Override
    void delBasic(TFunction obj) throws Exception {
        TFunction func = new TFunction(id: (obj as TFunction).id, isActive: CommonConstant.IsActive.FALSE.getValue())
        baseMapper.updateByPrimaryKeySelective(func);
    }
}
